/*
 * @Description: 运行时配置 名称定死的
 * @version: 1.0
 * @Author: ziwei
 * @Date: 2021-08-13 20:50:20
 * @LastEditors: ziwei
 * @LastEditTime: 2021-08-15 00:09:19
 */

//给路由配置对象打补丁
/* export function patchRoutes({routes}){
    routes.unshift({
        path:'/foo',
        exact:true,
        componnet:require('./Foo').default
    })
    console.log('route',routes);
} */

//modifyClientRenderOpts render都是定死的
//希望路由是后端返回的
let extraRoutes;
export  function modifyClientRenderOpts(opts) {
    console.log("before",opts.routes.length);
    opts.routes.unshift(...extraRoutes);
    console.log("after",opts.routes.length);
    return opts;
}
export function render(oldRender) {
    fetch('/api/routes').then(res => res.json()).then((res) => { 
        extraRoutes = res.map(item=>{
            let component = item.component;
            component = require(`./${component}`).default;
            return { ...item, component};
        });
        oldRender();
    })
}